package com.bibrApp.difu.actvity.register_mvp;

import android.content.Context;

import com.bibrApp.difu.Config;
import com.bibrApp.difu.Response.RegisterResBody;
import com.bibrApp.difu.api.RetrofitNet;
import com.bibrApp.difu.base.BaseObserver;
import com.bibrApp.difu.base.BasePresenter;
import com.bibrApp.difu.base.BaseReponse;
import com.bibrApp.difu.base.NewBaseReponse;
import com.bibrApp.difu.utils.DialogUtils;
import com.bibrApp.difu.utils.EncryptUtils;
import com.bibrApp.difu.utils.ToastUtils;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class RegisterPresenter extends BasePresenter<IRegisterView> {
    public RegisterPresenter(Context context, IRegisterView iView) {
        super(context, iView);
    }


    /**
     * 获取验证码
     *
     * @param mobile
     */
    public void getCode(String mobile) {
        DialogUtils.showDialog(context);
        HashMap<String, Object> map = new HashMap<>();
        map.put("mobile", mobile);
        map.put("noteType", Config.BASE_URL+Config.GET_GISTER_CODE_URL);
        RetrofitNet.getInstance()
                .getApi()
                .getVerifyCode(EncryptUtils.encryptNewType(map))
                .compose(getActivityLifecycleProvider().bindToLifecycle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new BaseObserver<Object>(context) {

                    @Override
                    protected void onSuccess(Object value) {
                        if(value != null){
                            ToastUtils.ShowToast(context,String.valueOf(value));
                        }

                    }
                });

    }
}
